unit SLVtypes ;

interface

uses
   SysUtils ;

type

   TSLVType = (
      slv0 = 0,                         // Forcing 0
      slv1 = 1,                         // Forcing 1
      slvL = 2,                         // Weak 0
      slvH = 3,                         // Weak 1

      slvX = 7,                         // Unknown

      slvD = 12,                        // Don't care
      slvZ = 13,                        // High Impedance
      slvW = 14,                        // Weak Unknown
      slvU = 15                         // Uninitialized
      ) ;

   TSLVArray = array of TSLVType ;
   pSLVArray = ^TSLVArray ;
   pSLVType = ^TSLVType ;

   TSigType = ( sgNone, sgSignal, sgVector, sgPort, sgDriver, sgInherent ) ;
   TPhases = ( cpRising, cpHigh, cpFalling, cpLow ) ;
   TStates = ( stFuture, stCurrent ) ;

   TSymbolType = (
      tyNone, tyRoot, tyEntity,
      tyPorts, tyComponents, tyCells, tySignals, tyAssignments,
      tyType, tyValue, tyAssignment,
      tySignal, tySource, tyVector, tySignalPort, tyVectorPort,
      tyParam, tyComponent, tyAttribute, tyCell, tySink,
      tyInits, tyInitLine
      ) ;
   TSymbolTypes = set of TSymbolType ;
   TPortType = ( ptNone, ptLeft, ptTop, ptRight, ptBottom ) ;
   TPortMode = ( pmNone, pmIn, pmOut, pmInout, pmBuffer, pmLinkage, pmClk ) ;
   TPortPos = record
      index : integer ;
      edge : TPortType ;
   end ;

   TBWMType = ( bwmNoChange, bwmWriteFirst, bwmReadFirst ) ;

   TRangeType = ( rtScalar, rtEmpty, rtSingle, rtDownto, rtTo ) ;
   TRange = packed record
      aType : TRangeType ;
      aLeft : smallint ;
      aRight : smallint ;
      aIndex : smallint ;
   end ;

   TRedrawEvent = procedure of object ;
   TOnProgessEvent = procedure( aProgress : integer ) of object ;

   IStructViewer = interface
      function GetCellText( column : integer ) : string ;
      function GetImageIndex : integer ;
   end ;

   IHierViewer = interface
      function GetCellText( column : integer ) : string ;
   end ;

   TInterfacedObj = class( TObject, IUnknown )
   protected
      function QueryInterface( const IID : TGUID ; out Obj ) : HResult ; stdcall ;
      function _AddRef : Integer ; stdcall ;
      function _Release : Integer ; stdcall ;
   end ;

   EElabor = class( Exception ) ;
   EEval = class( Exception ) ;
   EDeclaration = class( Exception ) ;
   ESim = class( Exception ) ;
   ENGC = class( Exception ) ;

const
   INTERNAL         = '(internal error, please report to tools@mediatronix.com)' ;
   BWMTypeAsString  : array[ TBWMType ] of string = (
      'NO_CHANGE', 'WRITE_FIRST', 'READ_FIRST' ) ;

var
   SimTime          : int64 = 0 ;

function Min( a, b : integer ) : integer ;
function Max( a, b : integer ) : integer ;

implementation

function TInterfacedObj.QueryInterface( const IID : TGUID ; out Obj ) :
   HResult ;
begin
   if GetInterface( IID, Obj ) then
      Result := 0
   else
      Result := HResult( $80004002 ) ;  // E_NOINTERFACE
end ;

function TInterfacedObj._AddRef : Integer ;
begin
   Result := 1 ;
end ;

function TInterfacedObj._Release : Integer ;
begin
   Result := 1 ;
end ;

function Min( a, b : integer ) : integer ;
begin
   if a < b then
      Result := a
   else
      Result := b ;
end ;

function Max( a, b : integer ) : integer ;
begin
   if a > b then
      Result := a
   else
      Result := b ;
end ;

end.

